package com.ss.android.action;

import android.content.Context;
import android.net.Uri;

import com.bytedance.common.utility.Logger;
import com.ss.android.common.AbsApiThread;
import com.ss.android.common.app.AbsApplication;
import com.ss.android.common.util.NetworkUtils;

import org.json.JSONObject;

import java.io.IOException;

public final class ActionThread extends AbsApiThread {
    private final String a;
    private final long b;
    private final int c;
    private final Context d;

    public ActionThread(Context arg3, long arg4, int arg6) {
        super(true);
        this.a = arg3.getResources().getConfiguration().locale.getLanguage();
        this.b = arg4;
        this.c = arg6;
        this.d = AbsApplication.getApplication();
    }

    public final void run() {
        int v0_2;
        String v1;
        try {
            StringBuilder v0_1 = new StringBuilder("http://ichannel.snssdk.com/service/1/app_alert_action/");
            v0_1.append("?rule_id=").append(this.b);
            if (!android.support.design.a.isTextEmpty(this.a)) {
                v0_1.append("&lang=").append(Uri.encode(this.a));
            }

            v0_1.append("&action=").append(this.c);
            v1 = v0_1.toString();
            v0_2 = 0;
            while (true) {
                label_21:
                if (v0_2 >= 4) {
                    return;
                }
                try {
                    if (!NetworkUtils.isNetworkAvailable(this.d)) {
                        Thread.sleep(3000);
                    }
                    Logger.v("ActionThread", v0_2 + " url: " + v1);
                    String v2_2 = NetworkUtils.doGet(10240, v1);
                    if (v2_2 == null) {
                        return;
                    }

                    if (v2_2.length() == 0) {
                        return;
                    }

                    JSONObject v3 = new JSONObject(v2_2);
                    if (isApiSuccess(v3)) {
                        return;
                    }

                    Logger.d("ActionThread", "app_alert_action error: " + v3);
                    return;

                } catch (IOException v2_1) {
                    ++v0_2;
                    continue;
                } catch (Exception v0) {
                    v1 = "ActionThread";
                    String v0_3 = "app_alert exception: " + v0;
                    Logger.w(v1, v0_3);
                    return;
                }

            }
        } catch (Exception v0) {
            v1 = "ActionThread";
            String v0_3 = "app_alert_action exception: " + v0;
            Logger.w(v1, v0_3);
            return;
        }
    }
}

